# 1 "../Equipment unit/mpu/Smooth_Filter.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 397 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "../Equipment unit/mpu/Smooth_Filter.c" 2
# 1 "../Equipment unit/mpu/Smooth_Filter.h" 1
# 18 "../Equipment unit/mpu/Smooth_Filter.h"
typedef struct {

 float raw_data[64];



 int dp;
 int pointer;
} SmoothFilter_t;

int SmoothFilter_Init(SmoothFilter_t *smooth_filter, int dp);
float SmoothFilter_Calc(SmoothFilter_t *smooth_filter, float data);
# 2 "../Equipment unit/mpu/Smooth_Filter.c" 2







int SmoothFilter_Init(SmoothFilter_t *smooth_filter, int dp) {
 int i;

 if(dp > 64)
  return 1;




 smooth_filter->dp = dp;
 smooth_filter->pointer = 0;
 for(i = 0; i < 4; i++) {
  smooth_filter->raw_data[i] = 0;
 }
 return 0;
}







float SmoothFilter_Calc(SmoothFilter_t *smooth_filter, float data) {
 int i;
 float ave = 0;
 smooth_filter->raw_data[smooth_filter->pointer] = data;
 if(++smooth_filter->pointer == smooth_filter->dp)
  smooth_filter->pointer = 0;
 for(i = 0; i < smooth_filter->dp; i++) {
  ave += smooth_filter->raw_data[i];
 }
 ave /= smooth_filter->dp;
 return ave;
}
